@@ -30,6 +30,10 @@ public class BluetoothDeviceListAdapter extends BaseAdapter {
|
||
| 30 | 30 |
notifyDataSetChanged(); |
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
+ public ArrayList<BluetoothDevice> getDeviceList(){
|
|
| 34 |
+ return deviceList; |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 33 | 37 |
public void addDevice(BluetoothDevice device){
|
| 34 | 38 |
if(this.deviceList==null){
|
| 35 | 39 |
this.deviceList = new ArrayList<>(); |
@@ -74,6 +78,7 @@ public class BluetoothDeviceListAdapter extends BaseAdapter {
|
||
| 74 | 78 |
BluetoothDevice device = deviceList.get(position); |
| 75 | 79 |
holder.deviceName.setText(device.getName()); |
| 76 | 80 |
holder.deviceMac.setText(device.getAddress()); |
| 81 |
+ holder.deviceStatus.setText(R.string.click_to_connect); |
|
| 77 | 82 |
return convertView; |
| 78 | 83 |
} |
| 79 | 84 |
|
@@ -6,6 +6,8 @@ import android.bluetooth.BluetoothDevice; |
||
| 6 | 6 |
import android.content.Intent; |
| 7 | 7 |
import android.os.Bundle; |
| 8 | 8 |
import android.support.annotation.Nullable; |
| 9 |
+import android.view.View; |
|
| 10 |
+import android.widget.AdapterView; |
|
| 9 | 11 |
import android.widget.ListView; |
| 10 | 12 |
import android.widget.TextView; |
| 11 | 13 |
import android.widget.Toast; |
@@ -21,7 +23,7 @@ import butterknife.ButterKnife; |
||
| 21 | 23 |
import butterknife.OnCheckedChanged; |
| 22 | 24 |
import butterknife.OnClick; |
| 23 | 25 |
|
| 24 |
-public class PrinterSettingActivity extends BaseActivity implements PrinterSettingContract.View {
|
|
| 26 |
+public class PrinterSettingActivity extends BaseActivity implements PrinterSettingContract.View,AdapterView.OnItemClickListener {
|
|
| 25 | 27 |
|
| 26 | 28 |
@BindView(R.id.listview_bt_devices) ListView btDevicesList; |
| 27 | 29 |
@BindView(R.id.tv_printer_status) TextView printerStatusText; |
@@ -42,7 +44,7 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
| 42 | 44 |
|
| 43 | 45 |
deviceAdapter = new BluetoothDeviceListAdapter(this); |
| 44 | 46 |
btDevicesList.setAdapter(deviceAdapter); |
| 45 |
- |
|
| 47 |
+ btDevicesList.setOnItemClickListener(this); |
|
| 46 | 48 |
presenter = new PrinterSettingPresenter(this,this); |
| 47 | 49 |
} |
| 48 | 50 |
|
@@ -148,4 +150,8 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
| 148 | 150 |
} |
| 149 | 151 |
} |
| 150 | 152 |
|
| 153 |
+ @Override |
|
| 154 |
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
| 155 |
+ presenter.connectBluetooth(deviceAdapter.getDeviceList().get(i)); |
|
| 156 |
+ } |
|
| 151 | 157 |
} |
@@ -20,6 +20,7 @@ public class PrinterSettingContract {
|
||
| 20 | 20 |
void discoverNewDevices(); |
| 21 | 21 |
void connectPrinter(); |
| 22 | 22 |
void cancelDiscovery(); |
| 23 |
+ void connectBluetooth(BluetoothDevice device); |
|
| 23 | 24 |
} |
| 24 | 25 |
|
| 25 | 26 |
public interface View{
|
@@ -103,6 +103,11 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
+ @Override |
|
| 107 |
+ public void connectBluetooth(BluetoothDevice device) {
|
|
| 108 |
+ |
|
| 109 |
+ } |
|
| 110 |
+ |
|
| 106 | 111 |
// changes the title when discovery is finished |
| 107 | 112 |
private final BroadcastReceiver mFindBlueToothReceiver = new BroadcastReceiver() {
|
| 108 | 113 |
@Override |
@@ -126,4 +131,6 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
| 126 | 131 |
} |
| 127 | 132 |
}; |
| 128 | 133 |
|
| 134 |
+ |
|
| 135 |
+ |
|
| 129 | 136 |
} |
@@ -33,6 +33,7 @@ |
||
| 33 | 33 |
android:id="@+id/tv_device_status" |
| 34 | 34 |
android:layout_width="wrap_content" |
| 35 | 35 |
android:layout_height="wrap_content" |
| 36 |
+ android:layout_marginRight="12dp" |
|
| 36 | 37 |
android:layout_gravity="center_vertical" |
| 37 | 38 |
android:textColor="@color/grey" |
| 38 | 39 |
android:textSize="14sp" /> |
@@ -96,4 +96,8 @@ |
||
| 96 | 96 |
<string name="printer_is_connected">已连接打印机</string> |
| 97 | 97 |
|
| 98 | 98 |
<string name="printer_is_disconnected">已断开打印机</string> |
| 99 |
+ |
|
| 100 |
+ <string name="click_to_connect">点击连接</string> |
|
| 101 |
+ |
|
| 102 |
+ <string name="connecting">尝试连接中</string> |
|
| 99 | 103 |
</resources> |